package API.ExceptionAPI.Practise.ThrowInClass;

public class Student {
    private String name;
    private int age;

    public Student() {
    }

    public Student(int age, String name) {
        if (name.length() < 2 || name.length() > 10) {
            throw new RuntimeException("Name must be between 2 and 10 characters");
        }
        if (age < 0 || age > 140) {
            throw new RuntimeException("Invalid age");
        }
        this.age = age;
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) throws RuntimeException {
        if (name.length() < 2 || name.length() > 10) {
            throw new NameFormatException("Name's length must be between 2 and 10 characters");
        }
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws RuntimeException{
        if (age < 0 || age > 40) {
            throw new AgeOutOfBoundsException("Invalid age");
        }
        this.age = age;
    }
}
